package com.kaaction.modules.mer.api;

import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.kaaction.common.web.BaseController;
import com.kaaction.modules.mer.entity.MerCustomer;
import com.kaaction.modules.mer.service.MerCustomerService;

@Controller
@RequestMapping(value = "/api/v1/customerApi")
public class CustomerApiController extends BaseController{

	@Autowired
	MerCustomerService merCustomerService;
	
	
	/**
	 * 用户信息更新
	 * 
	 * @param request
	 * @param response
	 * @throws UnsupportedEncodingException
	 * @throws DocumentException
	 */
	@RequestMapping(value = "/customer")
	public void spuClassify(HttpServletRequest request, HttpServletResponse response)
			throws UnsupportedEncodingException, DocumentException {
		
		MerCustomer merCustomer = new MerCustomer();
		
		String thirdpartyType = request.getParameter("thirdpartyType");
		String thirdpartyId = request.getParameter("thirdpartyId");
		String gender = request.getParameter("gender");
		String nickname = request.getParameter("nickname");
		String photo = request.getParameter("photo");
		
		merCustomer.setThirdpartyType(thirdpartyType);
		merCustomer.setThirdpartyId(thirdpartyId);
		merCustomer.setGender(gender);
		merCustomer.setNickname(nickname);
		merCustomer.setPhoto(photo);
		merCustomerService.updOrInsCustomer(merCustomer);
		super.writeAjaxResponse(response,"");
	}
	
	
	/**
	 * 预算更新
	 * 
	 * @param request
	 * @param response
	 * @throws UnsupportedEncodingException
	 * @throws DocumentException
	 */
	@RequestMapping(value = "/updateWeddingBudget")
	public void updateWeddingBudget(HttpServletRequest request, HttpServletResponse response)
			throws UnsupportedEncodingException, DocumentException {
		
		MerCustomer merCustomer = new MerCustomer();
		
		String thirdpartyType = request.getParameter("thirdpartyType");
		String thirdpartyId = request.getParameter("thirdpartyId");
		Integer weddingBudget = Integer.valueOf(request.getParameter("weddingBudget"));
		
		merCustomer.setThirdpartyType(thirdpartyType);
		merCustomer.setThirdpartyId(thirdpartyId);
		merCustomer.setWeddingBudget(weddingBudget);
		merCustomerService.updateWeddingBudget(merCustomer);
		super.writeAjaxResponse(response,"");
	}
}
